<?php
// +----------------------------------------------------------------------
// | B5Yii2CMF V3.0 [快捷通用基础管理开发平台]
// +----------------------------------------------------------------------
// | Author=>冰舞 <357145480@qq.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace api\modules\admin\controllers\system;

use api\modules\admin\AuthController;
use api\utils\libs\CommonAction;
use common\extend\exception\B5HttpException;
use common\models\system\Notice;

class NoticeController extends AuthController
{
    use CommonAction;

    protected string $model = Notice::class;
    protected bool $validate = true;

    /**
     * 保存前处理操作人
     * @param Notice $model
     * @param string $type
     * @return string
     * @throws B5HttpException
     */
    protected function saveBefore(Notice $model, string $type): string
    {
        $user = $this->getUser();
        $model->update_by = $user->nick_name;
        if ($type == 'add') {
            $model->create_by = $user->nick_name;
        }
        if ($type == 'add' || $type == 'edit') {
            $model->summary = trim(mb_substr(strip_tags($model->content ?: ''), 0, 50));
        }
        return '';
    }
}
